<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" href="../css/css.css" />
		<link rel="stylesheet" href="css/style.css" />
		<script type="text/javascript" src="laydate/laydate.js" ></script>
		<script type="text/javascript" src="js/js.js" ></script>
		<script src="https://cdn.bootcss.com/jquery/2.1.0/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../js/ajaxFunction.js" type="text/javascript" charset="utf-8"></script>
		<title></title>
		<script>
		$(function() {
			page = 1; // 当前页数
			totalpage = 1;// 总页数
			getTaskInfo(1);
		})
		function getTaskInfo(spage){
			page = spage;
			page = page > totalpage ? totalpage : page;
			page = page < 1 ? 1 : page;
			$.ajax({
				url : '../DeliveryInfoServlet',
				method : 'post',
				dataType : 'json',
				data : {
					'page' : page,
					'startTime' : $('#beginDate').val(),
					'endTime' : $('#endDate').val(),
					'deliveryno' : $('#deliveryno').val(),
					'transportStatus' : "4",
					'applyStatus' : "2",
					'lackStatus' : "1",
					'addressee' : $('#addressee').val(),
					'payno' : $('#payno').val()
					},
				success : function(diliveryies) {
						var str = "<tr>" + 
						"				<th><input type=\"checkbox\" onclick=\"swapCheck()\"/></th>" +
						"				<th>申请发货日期</th>" + 
						"				<th>发货数量</th>" + 
						"				<th>发货单号</th>" + 
						"				<th>国内运费</th>" + 
						"				<th>付款编号</th>" + 
						"				<th>收件人</th>" + 
						"				<th>订单商品</th>" + 
						"				<th>商品价格</th>" + 
						"				<th>付款状态</th>" + 
						"				<th>购买时间</th>" + 
						"			</tr>  ";
						$.each(diliveryies, function(index,delivery,array){
							if (delivery.total == null){
								var oldTime = (new Date(delivery.date)).getTime();
							    var curTime = new Date(oldTime).Format("yyyy-MM-dd");
								str +="<tr>" + 
								"	<td rowspan=\""+delivery.number+"\" class=\"tb_tr_center\"><input type=\"checkbox\" name='deliverynos' value='"+delivery.no+"'/></td>" +
								"	<td rowspan=\""+delivery.number+"\" class=\"text_center\">"+curTime+"</td>" + 
								"	<td rowspan=\""+delivery.number+"\" class=\"text_center\">"+delivery.number+"</td>" + 
								"	<td rowspan=\""+delivery.number+"\" class=\"text_center\"><a href='https://www.kuaidi100.com/chaxun?nu="+delivery.no+"'>"+delivery.no+"</a></td>"+
								"	<td rowspan=\""+delivery.number+"\" class=\"text_center\">"+delivery.freight+"</td>"+
								"	<td rowspan=\""+delivery.number+"\" class=\"text_center\">"+delivery.payNo+"</td>";
								$.each(delivery.tasks, function(index,task,array){
									oldTime = (new Date(task.time)).getTime();
								    curTime = new Date(oldTime).Format("yyyy-MM-dd");
								    str += "<td class=\"tb_tr_center\">"+task.addressee+"</td>";
									str += "	<td><img src=\"../"+task.goods.pic+"\" class=\"pic100 fl\"/>" + 
									"					<div class=\"fl ml10\">" + 
									"						<div>名称 : " + 
									"							<span>"+task.goods.name+"</span>" + 
									"						</div>" + 
									"						<div>品牌 : " + 
									"							<span>"+task.goods.brand+"</span>" + 
									"						</div>" + 
									"						<div>型号 : " + 
									"							<span>"+task.goods.type+"</span>" + 
									"						</div>" + 
									"						<div>颜色 : " + 
									"							<span>"+task.goods.color+"</span>" + 
									"						</div>" + 
									"						<div>尺码 : " + 
									"							<span>"+task.goods.size+"</span>" + 
									"						</div>" + 
									"						<div>数量 : " + 
									"							<span>"+task.goodsNumber+"</span>" + 
									"						</div>" + 
									"					</div>" + 
									"				</td>" + 
									"				<td>" + 
									"						<div>原价 : " + 
									"							<span class=\"red_span\>￥"+task.goods.price+"</span>" + 
									"						</div>" + 
									"					<div>单价 : <span class=\"red_span\">￥</span>" + 
									"						<span class=\"red_span\">"+task.price+"</span>" + 
									"						<span class=\"red_span\">(含国际)</span></div>" + 
									"					<div>国际运费 : <span class=\"red_span\">￥</span>" + 
									"						<span class=\"red_span\">"+task.freight+"</span>" + 
									"					</div>" + 
									"					<div>总价 : <span class=\"red_span\">￥</span>" + 
									"						<span class=\"red_span\">"+task.totalPrice+"</span>" + 
									"					</div>" + 
									"					<div>(付款请备注 : &nbsp;" + 
									"						<span>"+task.payNo+"</span>" + 
									"						)</div>" + 
									"				</td>" + 
									"				<td class=\"text_center\">" ;
									switch(task.payStatus){
									case '1': str += "未付款<br />";break;
									case '2': str += "已付款   <br />";break;
									case '3': str += "已退款  <br />";break;
									}
									switch(task.transportStatus){
									case '1': str += "<span class=\"red_span\">未发货</span> <br />";break;
									case '2': str += "<span class=\"red_span\">在途</span>  <br />";break;
									case '3': str += "<span class=\"red_span\">已到货</span>  <br />";break;
									case '4': str += "<span class=\"red_span\">已发货</span>  <br />";break;
									}
									switch(task.applyStatus){
									case '1': str += "未申请发货  <br />";break;
									case '2': str += "已申请发货  <br />";break;
									}
									switch(delivery.isPay){
									case '0': str += "国内运费未付  <br />";break;
									case '1': str += "国内运费已付  <br />";break;
									}
									str +="</td><td class=\"text_center\">"+curTime+"</td></tr><tr>";
								})
							}else{
								totalpage = delivery.total / 5;
								totalpage = totalpage > parseInt(totalpage) ? parseInt(totalpage) + 1 : totalpage;
								$('#total').empty();
								$('#total').append(delivery.total);
								$('#curpage').empty();
								$('#curpage').append(page);
								$('#totalpage').empty();
								$('#totalpage').append(totalpage);
							}
						});
						$('#taskTable').empty();
						$('#taskTable').append(str);
				}
			})
		}
		function postIsPay(){
			var deliverynos = [];
			if ($("input[name=deliverynos]:checked").length == 0){
				alert('请先选择需要操作的订单！');
				return;
			}
			$("input[name=deliverynos]:checked").each(function (index, item){
				deliverynos.push($(this).val());
			});
			$.ajax({
				url : '../DeliveryOperationServlet',
				method : 'post',
				data : {
					'operation' : 'isPay',
					'deliverynos' : deliverynos
				},
				traditional:true,
				success : function() {
					alert('操作成功！');
					getTaskInfo(page);
				}
			});
		}
		</script>
	</head>
	<body>
		<div class="main border-bottom-gray"><span class="fontBold"><a href="" class="mapsite">首页</a></span>&nbsp;/&nbsp;
		<span class="fontBold"><a href="" class="mapsite">发货管理</a></span>&nbsp;/&nbsp;未发货列表</div>
		<div class="border-bottom-gray main">
			<form action="" method="post">
				<div class="padding10_0">
					<span class="fontBold fontsize12">收件人 : </span><input id="addressee" type="text" class="input_text"  placeholder="请输入收件人"/>&nbsp;&nbsp;
					<span class="fontBold fontsize12">发货单号 : </span><input id="deliveryno" type="text" class="input_text"  placeholder="请输入订单编号"/>&nbsp;&nbsp;
					<span class="fontBold fontsize12">货单日期 : </span><input type="text" class="input_text" placeholder="请开始选择日期" id="beginDate"/>&nbsp;
					<span  class="fontBold fontsize12">至</span>&nbsp;
					<input type="text" class="input_text" placeholder="请选择截至日期" id="endDate"/>&nbsp;&nbsp;
					<span class="fontBold fontsize12">付款编号 : </span><input id="payno" type="text" class="input_text"  placeholder="请输入付款编号"/>&nbsp;&nbsp;
					<input type="button" onclick="getTaskInfo(1)" class="input_submit" value="查询"/>&nbsp;&nbsp;
					<input type="reset" class="whitebutton" value="重置"/>
				</div>
			</form>
		</div>
		<div class="main graybg">
			<form>
			<table class="tb_wid" id="taskTable">
			</table>
			<input type="button" value="国内运费已付" onclick="postIsPay()" class="input_submit"/>
		</form>
		<!-- <div align="left" valign="top" class="fenye">
			<span id="total"></span>条数据 <span id="curpage"></span>/<span id="totalpage"></span> 页&nbsp;&nbsp;
			<a href="javascript:void(0)" target="mainFrame" onfocus="this.blur()" onclick="getTaskInfo(1)">首页</a>&nbsp;&nbsp;
			<a href="javascript:void(0)" target="mainFrame" onfocus="this.blur()" onclick="getTaskInfo(--page)">上一页</a>&nbsp;&nbsp;
			<a href="javascript:void(0)" target="mainFrame" onfocus="this.blur()" onclick="getTaskInfo(++page)">下一页</a>&nbsp;&nbsp;
			<a href="javascript:void(0)" target="mainFrame" onfocus="this.blur()" onclick="getTaskInfo(totalpage)">尾页</a>
        </div> -->
		</div>
	</body>
	<script>
		laydate.render({
		  elem: '#endDate'
		});
		laydate.render({
		  elem: '#beginDate'
		});
	</script>
</html>
